package com.example.dao;

import com.example.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
//用户的增删改查
public interface UserMapper {
    @Select("SELECT * FROM user WHERE email = #{email} AND password = #{password} AND status = 'active'")
    @Results(id = "userMap", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "username", property = "username"),
            @Result(column = "password", property = "password"),
            @Result(column = "email", property = "email"),
            @Result(column = "register_time", property = "registerTime"),
            @Result(column = "role", property = "role"),
            @Result(column = "status", property = "status")
    })
    User login(User user);
    //  注册
    @Insert("INSERT INTO user (username, password, email, role, status) VALUES (#{username}, #{password}, #{email}, #{role}, #{status})")
    void register(User user);
    //  查询所有用户
    @Select("SELECT * FROM user")
    @ResultMap("userMap")
    List<User> findAll();
    //  修改用户状态
    @Update("UPDATE user SET status = #{status} WHERE id = #{id}")
    void updateStatus(@Param("id") Integer id, @Param("status") String status);

    // 新增方法
    @Select("SELECT * FROM user WHERE id = #{id}")
    @ResultMap("userMap")
    User findById(@Param("id") Integer id);

    // 新增：更新密码方法
    @Update("UPDATE user SET password = #{password} WHERE id = #{id}")
    void updatePassword(@Param("id") Integer id, @Param("password") String password);
}
